/*
 * The Seek Steering Behaviour
 */
class Seek extends Steering {
  
  // Target
  PreyAgent target;
  
  // Initialisation
  Seek(HunterAgent a, PreyAgent p) {
      super(a);
      this.target = p;
  }
  
  PVector calculateRawForce() {

      endDemoTime = System.currentTimeMillis();
      captureTime = (endDemoTime - startDemoTime) / 1000.0;
      if (captureTime > 5) {
         System.out.println("Timeout for catching the prey expired");
         noLoop();
         restartDemo();
         return new PVector(0,0);
      }

      // Check that agent's centre is not over target
      if (PVector.dist(this.target.position, agent.position) > this.target.radius) {
        // Calculate Seek Force
        PVector seek = PVector.sub(this.target.position, agent.position);
        seek.normalize();
        seek.mult(agent.maxSpeed);
        seek.sub(agent.velocity);
        return seek;
      } else  {
        // If agent's centre is over target stop seeking, the hunter caught the prey
        noLoop();
        restartDemo();
        return new PVector(0,0);
      }   
  }
  
  // Draw the target
  void draw() {
     pushStyle();
     fill(204, 153, 0);
     ellipse(this.target.position.x, this.target.position.y, this.target.radius, this.target.radius);
     popStyle();
  }

  void setTarget(PreyAgent target) {
      this.target = target;
  }
}
